package com.base.core.framework.typehandle;

import java.lang.reflect.Field;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.gitee.magic.context.ConverterEditorUtils;
import com.gitee.magic.core.json.JsonObject;

@MappedTypes({ Object.class })
@MappedJdbcTypes(JdbcType.VARCHAR)
public class ObjectClassTypeHandler extends AbstractJsonTypeHandler<Object> {

	public ObjectClassTypeHandler(Class<?> type) {
		super(type);
	}

	public ObjectClassTypeHandler(Class<?> type, Field field) {
		super(type, field);
	}

	@Override
	public Object parse(String json) {
		return ConverterEditorUtils.restoreObject(type, new JsonObject(json));
	}

	@Override
	public String toJson(Object obj) {
		// 对象转字符
		return ConverterEditorUtils.converterObject(obj).toString();
	}
	
}
